package main

import (
	"fmt"
	"strconv"
	"sync"
	"time"
)

var wg sync.WaitGroup

func main() {
	// 定义并初始化管道
	var channel chan int
	channel = make(chan int, 25)
	fmt.Printf("make--ch addr %v \n", channel)

	// 两个协程
	wg.Add(2)

	// 开启写协程
	go writData(channel)

	// 查看一下chnnel里有啥

	//	开启读协程
	go readData(channel)

	wg.Wait()
	fmt.Println("程序指向完毕")
}
func writData(ch chan int) {
	fmt.Printf("writData--ch addr %v \n", ch)
	for i := 0; i < 25; i++ {
		ch <- i + 5
		time.Sleep(time.Second)
	}
	close(ch)
	wg.Done()
}
func readData(ch chan int) {
	fmt.Printf("readData--ch addr %v \n", ch)
	for data := range ch {
		fmt.Printf(strconv.Itoa(data) + "\n")
		time.Sleep(time.Second)
	}
	wg.Done()
}
